<?php
namespace App\Common\Cla\Com\Api;

use App\Common as com;
use App as nameApp;
use App\Common\Server\Api\Gateway as nameApiGateway;

class Test extends com\Cla\ClaBase {

	/**
	 * @param string $apiName
	 * @param array $apiParam
	 * @return nameApiGateway\ApiResponse
	 */
	public static function callApiOfMiniProgram( string $apiName, array $apiParam = [] ):nameApiGateway\ApiResponse {
		$postParam = [];
		// api参数
		$postParam['mode'] = 'test';
		$postParam['api'] = $apiName;
		$postParam['apiParam'] = $apiParam;
		$request = com\Lib\Hyperf\Request::withQueryParams( $postParam );
		//
		// 初始化网关
		$apiGateway = nameApiGateway::newClassOfWebApi( $request );
		// 设置参数
		$apiGateway->apiRouter()->apiRequest()->setApiPrefix( 'user.member.miniProgram.' );
		$apiGateway->goApiRequest()->accessToken()->session()->set( [
			'userMemberId' => 6,
			'userCourierId' => 1,
			'debug' => [
				'skipCheckAuth' => 1,
			],
		] );
		// 处理
		$apiResponse = $apiGateway->handle();
		return $apiResponse;
	}

	/**
	 * @param string $apiName
	 * @param array $apiParam
	 * @return nameApiGateway\ApiResponse
	 */
	public static function callApiOfCommonManageOfAdmin( string $apiName, array $apiParam = [] ):nameApiGateway\ApiResponse {
		$postParam = [];
		// api参数
		$postParam['mode'] = 'test';
		$postParam['api'] = $apiName;
		$postParam['apiParam'] = $apiParam;
		com\Lib\Hyperf\Request::withQueryParams( $postParam );
		// 初始化网关
		$apiGateway = nameApiGateway::newClassOfWebApi();
		// 设置参数
		$apiGateway->apiRouter()->apiRequest()->setApiPrefix( 'user.webCommonManage.' );
		$apiGateway->goApiRequest()->accessToken()->session()->set( [
			'userType' => com\Cla\User\Admin::$userType,
			'userId' => 1,
			'debug' => [
				'skipCheckAuth' => 1,
			],
		] );
		// 处理
		$apiResponse = $apiGateway->handle();
		return $apiResponse;
	}


	/**
	 * @param string $apiName
	 * @param array $apiParam
	 * @return nameApiGateway\ApiResponse
	 */
	public static function callApiOfCommonManageOfLeague( string $apiName, array $apiParam = [] ):nameApiGateway\ApiResponse {
		$postParam = [];
		// api参数
		$postParam['mode'] = 'test';
		$postParam['api'] = $apiName;
		$postParam['apiParam'] = $apiParam;
		$request = com\Lib\Hyperf\Request::withQueryParams( $postParam );
		//
		// 初始化网关
		$apiGateway = nameApiGateway::newClassOfWebApi( $request );
		// 设置参数
		$apiGateway->apiRouter()->apiRequest()->setApiPrefix( 'user.webCommonManage.' );
		$apiGateway->goApiRequest()->accessToken()->session()->set( [
			'userType' => com\Cla\User\Company::$userType,
			'userId' => 1,
			'debug' => [
				'skipCheckAuth' => 1,
			],
		] );
		// 处理
		$apiResponse = $apiGateway->handle();
		return $apiResponse;
	}

}
